package com.violet.sharding.controller;

import com.violet.sharding.domain.AlarmDomain;
import com.violet.sharding.service.AlarmService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: wqf
 * @Date: 2023/01/09
 * @Description:
 */
@RestController
public class AlarmController {

    @Resource
    private AlarmService alarmService;

    @GetMapping("/alarm/list")
    public List<AlarmDomain> getList(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
                                     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @RequestParam LocalDateTime endTime) {
        return alarmService.queryList(startTime, endTime);
    }

    @GetMapping("/alarm/getOne")
    public AlarmDomain queryOne(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
                                     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @RequestParam LocalDateTime endTime) {
        return alarmService.queryOne(startTime, endTime);
    }

    @GetMapping("/alarm/save")
    public void save() {
         alarmService.save();
    }

    @GetMapping("/alarm/delete")
    public void delete(@RequestParam Long id) {
        alarmService.delete(id);
    }

}
